﻿using System.Collections;
using UnityEngine;
using Zenject;

/**
 * BattleScene和ShopScene来回切换管理器
 */
public class WaveManager : MonoBehaviour
{
    private int _wave;
    private int _waveTime;
    [Inject] private GameManager _gameManager;
    public void Init()
    {
        _wave = 0;
        _waveTime = 0;
    }

    public void WaveIncrease()
    {
        _wave++;
        _waveTime = 15 + _wave * 5;
        RxEventBus.Publish(new WaveTimeChangeEvent(_wave, _waveTime));
    }


    public IEnumerator StartWave()
    {
        while (true)
        {
            if (_waveTime <= 0)
            {
                break;
            }

            yield return new WaitForSeconds(1);
            _waveTime--;
            RxEventBus.Publish(new WaveTimeChangeEvent(_wave, _waveTime));
        }


        // check
        if (_wave == 30)
        {
            RxEventBus.Publish(new GameWinEvent());
        }

        if (!_gameManager.currentPlayer.GetComponent<PlayerHealth>().isDead)
        {
            RxEventBus.Publish(new WaveWinEvent());
        }
        else
        {
            RxEventBus.Publish(new GameOverEvent());
        }
    }
}